package org.grayrabbit.cms.action.search;

import net.sf.json.JSONObject;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.grayrabbit.cms.action.common.SimpleAction;
import org.grayrabbit.cms.service.lucene.impl.IndexTaskUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


@Controller
@Scope("prototype")
@Results( {@Result(name = "input", type = "dispatcher", location = "lucene-input.jsp")})
public class LuceneAction extends SimpleAction{

	private static final long serialVersionUID = 1L;
	
	@Autowired
	@Qualifier("indexTaskUpdate")
	private IndexTaskUpdate itu ;
	
	private String msg;
	
	
	@Action("lucene-input")
	public String input(){
		msg = IndexTaskUpdate.getMsg();
		return INPUT;
	}
	
	@Action("lucene-ajaxall")
	public String ajaxAll(){
		boolean flag = itu.createAll();
		JSONObject js = new JSONObject();
		js.put("flag", flag);
		js.put("msg", IndexTaskUpdate.getMsg()+",请稍后!");
		return renderHtml(js.toString());
	}
	
	
	@Action("lucene-ajaxcontent")
	public String ajaxContent(){
		boolean flag = itu.createContent();
		JSONObject js = new JSONObject();
		js.put("flag", flag);
		js.put("msg", IndexTaskUpdate.getMsg()+",请稍后!");
		return renderHtml(js.toString());
	}
	
	@Action("lucene-ajaxhtml")
	public String ajaxHtml(){
		boolean flag = itu.createHtml();
		JSONObject js = new JSONObject();
		js.put("flag", flag);
		js.put("msg", IndexTaskUpdate.getMsg()+",请稍后!");
		return renderHtml(js.toString());
	}
	
	@Action("lucene-ajaxkeywords")
	public String ajaxKeywords(){
		boolean flag = itu.createKeywords();
		JSONObject js = new JSONObject();
		js.put("flag", flag);
		js.put("msg", IndexTaskUpdate.getMsg()+",请稍后!");
		return renderHtml(js.toString());
	}
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
